<!DOCTYPE html>
<html lang="zh-cmn-Hans">
  <head>
    <meta charset="UTF-8">
    <meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport" />
    <meta content="yes" name="apple-mobile-web-app-capable" />
    <meta content="black" name="apple-mobile-web-app-status-bar-style" />
    <meta name="format-detection" content="telephone=no" />
    <link rel="stylesheet" href="../../../static/mobile/default/css/layout.css?v=2"/>
    <link rel="stylesheet" href="../../../static/assets/css/zpui.css" />
    <script type="text/javascript" src="https://res.wx.qq.com/open/js/jweixin-1.3.2.js"></script>
    <link rel="icon" type="image/png" href="../../../static/favicon.ico"/>
        <script src="../../../static/js/jquery/jquery/2.1.4/jquery.min.js"></script>
    <script src="../../../static/js/jquery/jquery.cookie.js"></script>
    <script src="../../../static/mobile/default/js/page.js?v=1"></script>
    <script src="http://res.wx.qq.com/open/js/jweixin-1.4.0.js"></script>
    <title>电子合同  - 达漂亮</title>
          
<link rel="stylesheet" href="../../../static/mobile/default/css/orderDetails.css" />


</head>
<body >
  <div class="page myOrder">
    		<div class="page-hd">
            <div class="header base-header bor-1px-b">
                <div class="header-left">
                    <a href="javascript:history.go(-1)" class="left-arrow"></a>
                </div>
                <div class="header-title">电子合同</div>
                <div class="header-right">
                    <!-- <a href=""></a> -->
                </div>
            </div>
        </div>
      
<div class="page-bd">
    <!-- 页面内容-->
    <div class="tab fs32">
        <div class="color_9 orderActive" data-type="1">待甲方签</div>
        <div class="color_9" data-type="2">待乙方签</div>
        <div class="color_9" data-type="3">已完成</div>
        <div class="color_9" data-type="4">已过期</div>
    </div>
    <div class="tabBox">
        <div class="block 1Box"></div>
        <div class="block box 2Box"></div>
        <div class="block box 3Box"></div>
        <div class="block box 4Box"></div>
    </div>
</div>
  <div class="bottom-tabbar-wrapper">
            <div class="bottom-tabbar">
                <a href="./contract.html" class="bottom-tabbar__item active">
                    <span class="icon">
                        <img src="../../../static/menuimg/footer_index_a.png" />
                        <img class="lhimg" src="../../../static/menuimg/footer_index_b.png" />
                    </span>
                    <p class="label">电子合同</p>
                </a>
                <a  class="bottom-tabbar__item Initiatingcontract">
                    <span class="icon">
                        <img src="../../../static/menuimg/footer_cat_a.png" />
                        <img class="lhimg" src="../../../static/menuimg/footer_cat_b.png" />
                    </span>
                    <p class="label">发起合同</p>
                </a>
            </div>
        </div>
<!-- 没有相关订单-->
<script type="text/html" id="emptyTpl">
    <div class="empeyOrder">
        <img src="../../../static/mobile/default/images/emptyData.png" alt="">
        <span class="fs28 color_3">暂无相关合同</span>
    </div>
</script>

<script type="text/html" id="orderTpl">
    {{each data as item index}}
    <div class="orderBox" style='margin-bottom: 0.133333rem; background-color: #fff;'>
        <a href="./contractDetail.html?contractId={{item.id}}">
            <div class="code fs28">
                <p class="color_3" data-id='{{item.id}}'>合同名称:{{item.contractName}}</p>
                {{if item.status == 1}}
                <span class="color_9 ostatus">待甲方签</span>
                {{/if}}
                 {{if item.status == 2}}
                <span class="color_9 ostatus">待乙方签</span>
                {{/if}}
                 {{if item.status == 3}}
                <span class="color_9 ostatus">已完成</span>
                {{/if}}
                 {{if item.status == 4}}
                <span class="color_9 ostatus">已过期</span>
                {{/if}}
            </div>
            <div class="goodslist">
                <div class="goods">
                    <div class="goodsinfo">
                        <p class="fs28 color_3">发起人签：{{item.sendUserName}}</p>
                        <p class="fs28 color_3">接收人签：{{item.recvUserName}}</p>
                        <p class="fs28 color_3">签署有效期：{{item.endTime}}</p>
                      
                    </div>
                </div>
            </div>
        </a>


    </div>
    {{/each}}
</script>
<script>
    var nowPage = [],getAgain = [],isLoadend = [];
   var _type = '1';
    var  user_id = getUrlParam('user_level_id')?getUrlParam('user_level_id'):''
    
    
    $('.Initiatingcontract').click(function(){
        
         if (user_id == 1) {
                _alert('您当前等级为游客，暂不能发起合同')
                return
            } else if (user_id == 2) {
                 _alert('您当前等级为VIP，暂不能发起合同')
                return
            }
            window.location.href="./Initiatingcontract.html"
    })
    console.log('user_id',user_id)
         share()
     function  share(){
    /***用户点击分享到微信圈后加载接口接口*******/
        var url=window.location.href;
        console.log("url:"+url);
            $.ajax({
		    url: "/api/mp/wxconfig",
		    type: "post",
		    data:{shareUrl:url},
		    headers:{ token: $.cookie('code')},
		    dataType: "json",
		    success: function(data){
		         configData = {
                    debug : false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来，若要查看传入的参数，可以在pc端打开，参数信息会通过log打出，仅在pc端时才会打印。
                    appId: data.data.appid, // 必填，公众号的唯一标识
                    timestamp: data.data.timestamp, // 必填，生成签名的时间戳
                    nonceStr: data.data.nonceStr, // 必填，生成签名的随机串
                    signature: data.data.signature,// 必填，签名，见附录1
                    jsApiList : ['hideOptionMenu']
                    // 必填，需要使用的JS接口列表，所有JS接口列表见附录2
               };
               
               //step2:注入配置信息
               wx.config(configData);
               //step3:通过ready接口处理成功验证
               wx.ready(function () {
                   // config信息验证后会执行ready方法，所有接口调用都必须在config接口获得结果之后，config是一个客户端的异步操作，所以如果需要在页面加载时就调用相关接口，则须把相关接口放在ready函数中调用来确保正确执行。对于用户触发时才调用的接口，则可以直接调用，不需要放在ready函数中。
//                 alert("执行ready方法");
//                 wx.checkJsApi({
//                      jsApiList: ['chooseImage'] // 需要检测的JS接口列表，所有JS接口列表见附录2,
//                      success: function(res) {
//                      // 以键值对的形式返回，可用的api值true，不可用为false
//                      // 如：{"checkResult":{"chooseImage":true},"errMsg":"checkJsApi:ok"}
//                      }
//                 });
                   //接口1:获取网络类型
                    wx.getNetworkType({
                        success: function (res) {
                          oldNet = res.networkType; // 返回网络类型2g，3g，4g，wifi
//                        alert("网络类型"+ oldNet);
                        }
                     });
                   //禁用右上角菜单按钮
                   wx.hideOptionMenu();
		    })
		    },
		    error: function() {
// 			    _alert('ajax request failed!!!!');
			    return;
		    } 
        })

	    
	    
	    }
    $(function(){
        $('.left-arrow').on('click',function(){
            window.location.href = '/member/center/index.html';
        })
        $('.page-bd').scroll(function(){
            var box_h=$(this).height()
            var content_h=$('.scrollBox').height()
            var scroll_h=$(this).scrollTop();
            if(content_h-box_h-scroll_h<20){
                getList();
            }
        })
		
		$('.tabBox').on('click','.order_review',function(){
			var order_id = $(this).data('order_id');
			 window.location.href = '/shop/comment/index/order_id/'+order_id+'.html';
		})
		
        //请求列表数据
        function getList(isagain) {
            page = nowPage[_type];
            if (typeof(page) == 'undefined') page = 1;
            if (isLoadend[_type] == true ) return false;
            if (isagain == true){
                if (getAgain[_type] == false) return false;
                getAgain[_type] = false;
            }else{
                $('.'+_type+'Box').append('<div class="get_list_tip" data-type="'+_type+'">加载数据中...</div>');
            }
            isLoadend[_type] = true;

            $.ajax({
                url:'https://mp.jianguoes.com/api/mp/pageContract',// 跳转到 action
                data:{page:page,size:10,status:_type},
                type:'get',
                headers:{'token': $.cookie('code')},
                dataType:'json',
                success:function(res) {
                    console.log(res);
                    isLoadend[_type] = false;
                    if(res.errno  != 0 ){
                        _alert(res.errmsg);
                        getAgain[_type] = true;
                        $('.'+_type+'Box').find('.get_list_tip').html('加载失败，点击重新加载.');
                        return false;
                    }
                   
                    $('.'+_type+'Box').find('.get_list_tip').remove();
                    if (res.data.data.length>0){
                        $('.'+_type+'Box').append(template('orderTpl',res.data));
                    }else{
                        $('.'+_type+'Box').html(template('emptyTpl'));
                    }

                    if (res.data.totalPages == page) {
                        $('.'+_type+'Box').append('<div class="get_list_tip">---我也有底线的---</div>');
                        isLoadend[_type] = true;
                    }else{
                         nowPage[_type] = page+1;
                    }
                },error : function() {
                    isLoadend[_type] = false;
                    getAgain[_type] = true;
                    $('.'+_type+'Box').find('.get_list_tip').html('加载失败，点击重新加载.');
                }
            });
        }
        //重新请求数据
        $(document).on('click','.get_list_tip',function () {
                _type = $(this).data('_type');
                getList(true);
        })
        //订单操作
        $('.tabBox').on('click','.order_action',function(){
            var _this = $(this);
            var arr = new Object();
            arr.order_id = _this.data('order_id');
            arr.type = _this.data('type');
			if (arr.type == 'cancel'){
				_alert('确定取消此订单？',function(){action(arr,_this)});
				return false;
			}
           return action(arr,_this);
        })
		function action(arr,_this){
		 	jq_ajax('/shop/api.order/action.html',arr,function(res){
				if(res.code  == 0 ){
					_alert(res.errmsg);
					return false;
				}
				_this.parents('.orderBox').remove();
			})	
		}
        $('.tab div').on('click',function(){
            var index=$(this).index();
            _type = $(this).data('type');
            if ($('.'+_type+'Box').html() == ''){
                isLoadend[_type] = false;
                getAgain[_type] = false;
                getList();//执行加载
            }
            $(this).addClass('orderActive')
            $(this).siblings().removeClass('orderActive')
            $('.block').eq(index).show();
            $('.block').eq(index).siblings().hide();
        })
        $('.tab div').each(function () {
            if ($(this).data('type') == _type){
                $(this).trigger('click');
                isLoadend[_type] = false;
                getAgain[_type] = false;
            }
        })
    })
</script>

  </div>

<script src="../../../static/js/art-template.js"></script>
<script src="../../../static/mobile/default/js/lib/fastclick.js"></script>
<script src="../../../static/js/jquery/lazyload/jquery.lazyload.js"></script>
<script>
    $(function() {
        FastClick.attach(document.body);
		$("img.lazy").lazyload({effect:"fadeIn",event:"scroll",container:$(".page-bd")});
    });
</script>

  <div class="alertBox">
      <div class="alertBG"></div>
      <div class="alert">
          <div class="text fs30 color_3 bor_b">

          </div>
          <!-- 单按钮 -->
          <div class="button fs32 fw_b color_r">
              知道了
          </div>
          <!-- 双按钮 -->
          <div class="buttonBox fs32 fw_b">
              <span class="color_9 bor_r cancel">取消</span>
              <span class="color_r confirm">确定</span>
          </div>
      </div>
  </div>
  <script type="text/javascript">
      var is_xcx = 0;
      $(document).on('click', 'a', function () {
          var href = $(this).attr('href');
          if (href.indexOf('/pages') != -1) {
              if (is_xcx == 1) {
                  wx.miniProgram.navigateTo({
                      url: href
                  })
                  return false;
              } else {
                  return false;
              }
          }
      })
  </script>
        <script type="text/html" id="payListTpl">
    <div class="block">
        <label for="other" style="width: 100%;">
            <div class="payType">
                <img src="../../static/mobile/default/images/balancePay.png" alt="">
                <div>
                    <span class="fs30 color_3">余额支付</span>
                    <span class="fs26 color_r">(￥{{mlsuser.allProfit}})</span>
                </div>
            </div>
        </label>
        <label for="other">
            <div class="iconBox">
                <input type="radio" class="check" name="pay_id" value="other" id="other">
                <i class="icon_checked"></i>
            </div>
        </label>
    </div>
    <div class="block">
        <label for="wxpay" style="width: 100%;">
            <div class="payType">
                <img src="../../static/mobile/default/images/weixinPay.png" alt="">
                <div>
                    <span class="fs30 color_3">微信支付</span>
                </div>
            </div>
        </label>
        <label for="wxpay">
            <div class="iconBox">
                <input type="radio" class="check" name="pay_id" value="wxpay" id="wxpay">
                <i class="icon_checked"></i>
            </div>
        </label>
    </div>
    
</script>


    <script src="../../../static/js/art-template.js"></script>

  <!-- 支付方式 -->
  <div class="payment">
        <div class="model payModel">
            <div class="modelContent">
                <div class="closeBox"><img src="../../static/mobile/default/images/close_icon.png" alt=""></div>
                <div class="title fs36 color_3 fw_b">请选择支付方式</div>
                <div class="cantre pay" id="payListBox">

                    <p class="get_list_tip">加载中...</p>

                </div>
                <div class="buttBox">
                    <span class="fs32 fw_b color_w BGcolor_r payConfirm">确认支付</span>
                </div>
            </div>
        </div>
</div>
         <link rel="stylesheet" href="../../../static/mobile/default/css/payment.css" />
        <link rel="stylesheet" href="../../../static/mobile/default/css/userData.css" />
        <script type="text/javascript">
        var orderId = ''
        var totalGoodsPrice = ''
        //选择支付方式
        function choosePay(that){
            orderId = that.attr('data-order_id') 
            totalGoodsPrice = that.attr('data-orderMoney')
             jq_ajax('https://mp.jianguoes.com/api/mp/getUserInfo', '', function (res) {
                    if (res.errno != 0) {
                        _alert(res.errmsg);
                        return false;
                    }
                    $('#payListBox').html(template('payListTpl', res.data));
                    $('.payModel').show();
                }, 'get');
               
        }
        
        $('.closeBox').on('click', function () {
                $('.model').hide();
            });
            
             //下单
            $('.buttBox .payConfirm').on('click', function (event) {
                
                var pay_id = $("input[name='pay_id']:checked").val();
                if (typeof (pay_id) == 'undefined' || pay_id < 1) {
                    _alert('请选择支付方式.');
                    return false;
                }
                
                

                    if(pay_id == 'other'){
                     jq_ajax('https://mp.jianguoes.com/api/mp/amountpay', {orderId:orderId}, function (res) {
                        if (res.errno != 0) {
                            _alert(res.errmsg);
                            return false;
                        }
                        
                         //支付成功跳转到支付成功页面,并不是真正到账
                        window.location.href = "https://mp.jianguoes.com/shop/flow/done/order_id/paysuccess.html?orderId="+orderId+'&orderMoney='+totalGoodsPrice;
                    }, 'get')
                }else{
                     jq_ajax('https://mp.jianguoes.com/api/mp/prepay', {orderId:orderId}, function (res) {
                        if (res.errno != 0) {
                            _alert(res.errmsg);
                            return false;
                        }
                        console.log(res);
                        onBridgeReady(res.data,orderId)
                        // window.location.href = '/shop/flow/done/order_id/done.html';
                    }, 'get')
                }
                
            event.stopPropagation()
            })
            
            
            
            function onBridgeReady(params,order_id) {
                console.log(params);
                WeixinJSBridge.invoke(
                    'getBrandWCPayRequest', {
                    "appId": params.appId,     //公众号名称，由商户传入     
                    "timeStamp": params.timeStamp,         //时间戳，自1970年以来的秒数     
                    "nonceStr": params.nonceStr, //随机串     
                    "package": params.package,
                    "signType": params.signType,         //微信签名方式：     
                    "paySign": params.paySign //微信签名 
                },
                    function (res) {
                        var last = JSON.stringify(res); //将JSON对象转化为JSON字符
                        if(res.err_msg === "get_brand_wcpay_request:ok" ) {
                            //支付成功跳转到支付成功页面,并不是真正到账
                            window.location.href = "https://mp.jianguoes.com/shop/flow/done/order_id/paysuccess.html?orderId="+order_id+'&orderMoney='+totalGoodsPrice;
                        }
                        if (res.err_msg === "get_brand_wcpay_request:cancel") {
                            //交易取消时需要更新账户和充值记录
                            window.location.href = "https://mp.jianguoes.com/shop/flow/done/order_id/payfail.html?orderId="+order_id+'&orderMoney='+totalGoodsPrice;
                        }
                        if (res.err_msg === "get_brand_wcpay_request:fail") {
                            //交易取消时需要更新账户和充值记录
                                window.location.href = "https://mp.jianguoes.com/shop/flow/done/order_id/payfail.html?orderId="+order_id+'&orderMoney='+totalGoodsPrice;
             }
                    });
            }
            // if (typeof WeixinJSBridge == "undefined") {
            //     if (document.addEventListener) {
            //         document.addEventListener('WeixinJSBridgeReady', onBridgeReady, false);
            //     } else if (document.attachEvent) {
            //         document.attachEvent('WeixinJSBridgeReady', onBridgeReady);
            //         document.attachEvent('onWeixinJSBridgeReady', onBridgeReady);
            //     }
            // } else {
            //     onBridgeReady();
            // }

        </script>
    </body>
</html>